<?php
defined( '_VALID_MOS' ) or die('<script>window.location.href="http://www.kinifurniture.com";</script>');

$adm_functions->is_admin_login();
$section='Add Product';

$adm_menu='
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td class="menudottedline" width="40%">
			<div class="pathway"><img src="assets/admin/'.$SITE_LOGO_ADMIN.'"/></div>	</td>
		<td class="menudottedline" align="right">
			<table cellpadding="0" cellspacing="0" border="0" id="toolbar">
				<tr valign="middle" align="center">
					<td>&nbsp;</td>
					<td>
					<a class="toolbar" href="javascript:kliksubmit();">
						<img src="show_files/save.png"  alt="Save" name="save" title="Save" align="middle" border="0" />				<br />Save</a>
					</td>
					<td>&nbsp;</td>
					<td>
						<a class="toolbar" href="admin.php?show=product_manager&coll='.$coll.'">
						<img src="show_files/cancel.png"  alt="Cancel" name="cancel" title="Cancel" align="middle" border="0" />				<br />Cancel</a>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<br />
';
if($inp_title)
{
	if($_FILES['inp_upl_img']['name'])
	{
		$img_name=basename($_FILES['inp_upl_img']['name']);
		$qryname="select * from produk where imglarge='$img_name'";
		$selectname=$dbh->query($qryname);
		$imageexists=mysql_num_rows($selectname);
		
		if($imageexists>0)
		{
			$val_title=$inp_title;
			if ($inp_sample=='Y') $val_select1='selected'; else $val_select2='selected';
			if ($inp_fsclabel=='Y') $val_select3='selected'; else $val_select4='selected';
			$val_selected_coll=$inp_collection;
			$val_size=$inp_size;
			$val_nr=$inp_nr;
			$val_description=$inp_description;
			echo '<script>alert("The Image Filename is already exists, try another filename");</script>';
		}
		else
		{
			$uploaddir = 'assets/product/';
			$uploadfile = $uploaddir . basename($_FILES['inp_upl_img']['name']);
			move_uploaded_file($_FILES['inp_upl_img']['tmp_name'], $uploadfile);
			$img_name=basename($_FILES['inp_upl_img']['name']);
		}
	} else 	$img_name='';
	if ($imageexists==0) 
	{
		$dbh->query("insert into produk (nr, koleksi, nama_produk, sample, fsclabel, keterangan, imglarge, size) values
			('$inp_nr', '$inp_collection', '$inp_title', '$inp_sample', '$inp_fsclabel', '$inp_description', '$img_name', '$inp_size')");
//		echo '<script>alert("Added New Product");</script>';
		echo '<script>window.location.href="admin.php?show=product_manager&coll='.$inp_collection.'";</script>';
	}
}

$val_select1='';
$val_select2='selected';
$val_select3='';
$val_select4='selected';

	$qrycoll="select * from koleksi";
	$Res=$dbh->query($qrycoll);
	$val_collection='';

	while($sqlRowcoll=mysql_fetch_object($Res))
	{
		$val_id_collection=$sqlRowcoll->id;
		$coll_name=$sqlRowcoll->nama;

		if ($inp_collection=='') $val_selected_coll=$coll;
		if ($val_id_collection==$val_selected_coll) $selected='selected'; else $selected='';
		$val_collection.='<option value="'.$val_id_collection.'" '.$selected.'>'.$coll_name.'</option>';
	}

?>